import { AxiosRequestConfig, AxiosResponse } from "axios";

export interface RequestInterceptors {
  // 请求拦截
  requestInterceptor?: (config: AxiosRequestConfig) => AxiosRequestConfig;
  // 请求异常拦截
  requestInterceptorCatch?: (err: any) => any;

  // 响应拦截
  responseInterceptor?: (config: AxiosResponse) => AxiosResponse;
  // 响应异常拦截
  responseInterceptorCatch?: (err: any) => any;
}

/***
 * 初始化实例配置
 */
export interface InitRequestConfig extends AxiosRequestConfig {
  // 拦截器对象
  interceptors?: RequestInterceptors;
}

export interface RequestConfig extends AxiosRequestConfig {
  hideLoading?: boolean;
  loadingText?: string;
  hideError?: boolean;
}

export interface BaseReponse<T> {
  code: number;
  message: string;
  result: T;
  success: boolean;
  timestamp: number;
}

export enum ConfigEnum {
  // TOKEN
  TOKEN = "X-Access-Token",
  // TIMESTAMP
  TIMESTAMP = "X-TIMESTAMP",
  // Sign
  Sign = "X-Sign",
  // 租户id
  TENANT_ID = "X-Tenant-Id",
  // 版本
  VERSION = "X-Version",
  // 低代码应用ID
  X_LOW_APP_ID = "X-Low-App-ID",
}

export enum CustomRespEnum {
  SUCCESS = 0,
  SUCCESS2 = 200,
  UNAUTH = 401,
}

//文件上传参数
export interface UploadFileParams {
  // 其他参数
  data?: Recordable;
  // 文件参数接口字段名
  name?: string;
  // 文件
  file: File | Blob;
  // 文件名
  filename?: string;
  [key: string]: any;
}

//文件返回参数
export interface UploadFileCallBack {
  // 成功回调方法
  success?: any;
  // 是否返回响应头,需要获取响应头时使用此属性
  isReturnResponse?: boolean;
}
